#include "StdAfx.h"
#include "ScramblerFactory.h"
#include "SgTranslate.h"
#include "sgcomposite.h"
#include "sgrotatearoundpoint.h"
#include "sgptr.h"
#include "sgseparator.h"
#include "sgtexture.h"
#include "sgcylinder.h"
#include "sgoctagonalcylinder.h"
#include "FerrisWheelFactory.h"
#include "graphics/GrVector.h"
#include "sgrotate.h"
#include "sgmaterial.h"

#define GR_PI 3.14159265358979323846

FerrisWheelFactory::FerrisWheelFactory(void)
{
	m_FerrisWheel = new CSgComposite();

	m_texture1 = new CTexture();
	m_texture1->LoadFile(L"marble03.bmp");
	m_texture2 = new CTexture();
	m_texture2->LoadFile(L"plank01.bmp");
	m_texture3 = new CTexture();
	m_texture3->LoadFile(L"marble10.bmp");
	m_texturesign = new CTexture();
	m_texturesign->LoadFile(L"ferris-wheel.bmp");
	m_wheelRotateDegrees = 0;
}

FerrisWheelFactory::~FerrisWheelFactory(void)
{
	delete m_texture1;
	delete m_texture2;
	delete m_texture3;
	delete m_texturesign;
}

void FerrisWheelFactory::AdvanceTime(const DWORD & timeDiff, const DWORD & currentTime)
{
	const int incrementDegrees = (int)((double)timeDiff / 30.);
	const unsigned mod = currentTime % 20000;

	if (mod <= 2000)
	{
		const double speed = 1.0 - ((double)(mod)/2000.);
		m_wheelRotateDegrees = fmod((m_wheelRotateDegrees + (incrementDegrees*speed)), 360.0);
	}
	else if (mod > 2000 && mod <= 3000)
	{
		
	}
	else if (mod > 3000 && mod <= 5000)
	{
		const double speed = ((double)(mod-3000)/2000.);
		m_wheelRotateDegrees = fmod((m_wheelRotateDegrees + (incrementDegrees*speed)), 360.0);
	}
	else
	{
		m_wheelRotateDegrees = fmod(m_wheelRotateDegrees + incrementDegrees, 360.0);
	}

	if (m_rotate_point_1 != NULL)
	{
		m_rotate_point_1->SetDegrees(m_wheelRotateDegrees);
	}

	if (m_rotate_point_5 != NULL)
	{
		m_rotate_point_5->SetDegrees(m_wheelRotateDegrees);
	}

	if (m_rotate_point_2 != NULL)
	{
		for (int i = 0; i < NUM_SEATS; i++)
		{
			//const double cur_angle = fmod(360.0/(double)NUM_SEATS * i + m_wheelRotateDegrees, 360.0);
			//m_rotate_point_2[i]->SetDegrees(-cur_angle);
			m_rotate_point_2[i]->SetDegrees(-m_wheelRotateDegrees);
		}
	}

	// animate 'lights' on the sign

	// X
	{
		// the mult/div improves 'accuracy' of mod here, when dealing with the imperfect timer...deal in 100ms not 1ms
		int oneToEnable = (currentTime % (NUM_LIGHTS_X*100)) / 100;
		for (int i = 0; i < NUM_LIGHTS_X; i++)
		{
			if (oneToEnable == i)
			{
				m_sign_mat_left[i]->SetMaterial(50.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
				m_sign_mat_right[NUM_LIGHTS_X-i-1]->SetMaterial(50.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
			}
			else
			{
				m_sign_mat_left[i]->SetMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
				m_sign_mat_right[NUM_LIGHTS_X-i-1]->SetMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
			}
		}
	}

	// Y
	{
		int oneToEnable = (currentTime % (NUM_LIGHTS_Y*100)) / 100;
		for (int i = 0; i < NUM_LIGHTS_Y; i++)
		{
			if (oneToEnable == i)
			{
				m_sign_mat_top[i]->SetMaterial(50.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
				m_sign_mat_bottom[NUM_LIGHTS_Y-i-1]->SetMaterial(50.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
			}
			else
			{
				m_sign_mat_top[i]->SetMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
				m_sign_mat_bottom[NUM_LIGHTS_Y-i-1]->SetMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
			}
		}
	}
}

CSgPtr<CSgComposite> FerrisWheelFactory::MakeSign()
{
	CSgPtr<CSgComposite> signc = new CSgComposite();
	const float r_z = 0.1f;


	CSgPtr<CSgSeparator> sep2 = new CSgSeparator();
	CSgPtr<CSgRotate> rot2 = new CSgRotate(270.0, 0, 0, 1);
	//CSgPtr<CSgTranslate> trans2 = new CSgTranslate(-SEAT_DEPTH, 0, 0);
	CSgPtr<CSgTranslate> trans2 = new CSgTranslate(-SIGN_HEIGHT, 0, 0);
	CSgPtr<CSgMesh> sign = new CSgMesh();


	// put lights all along the top
	for (unsigned i = 0; i < (unsigned)fabs(SIGN_DEPTH); i++)
	{
		CSgPtr<CSgMaterial> octmat = new CSgMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
		CSgPtr<CSgSeparator> octsep = new CSgSeparator();
		CSgPtr<CSgTranslate> octtrans = new CSgTranslate(0.5+(double)i, SIGN_HEIGHT + 0.05f, 0);
		CSgPtr<CSgOctagonalCylinder> octcyl = new CSgOctagonalCylinder(0.1f, 0.1f);

		m_sign_mat_top[i] = octmat;

		octmat->SetChild(octcyl);
		octtrans->SetChild(octmat);
		octsep->SetChild(octtrans);
		signc->AddChild(octsep);
	}
	
	// put lights all along the bottom
	for (unsigned i = 0; i < (unsigned)fabs(SIGN_DEPTH); i++)
	{
		CSgPtr<CSgMaterial> octmat = new CSgMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
		CSgPtr<CSgSeparator> octsep = new CSgSeparator();
		CSgPtr<CSgTranslate> octtrans = new CSgTranslate(0.5+(double)i, -0.05f, 0);
		CSgPtr<CSgOctagonalCylinder> octcyl = new CSgOctagonalCylinder(0.1f, 0.1f);

		m_sign_mat_bottom[i] = octmat;

		octmat->SetChild(octcyl);
		octtrans->SetChild(octmat);
		octsep->SetChild(octtrans);
		signc->AddChild(octsep);
	}

	// put lights all along the left side
	for (unsigned i = 0; i < (unsigned)fabs(SIGN_HEIGHT); i++)
	{
		CSgPtr<CSgMaterial> octmat = new CSgMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
		CSgPtr<CSgSeparator> octsep = new CSgSeparator();
		CSgPtr<CSgTranslate> octtrans = new CSgTranslate(-0.05f, 0.5+(double)i, 0); // cylinder is centered (0.05 = 0.1/2.)
		CSgPtr<CSgOctagonalCylinder> octcyl = new CSgOctagonalCylinder(0.1f, 0.1f);

		m_sign_mat_left[i] = octmat;

		octmat->SetChild(octcyl);
		octtrans->SetChild(octmat);
		octsep->SetChild(octtrans);
		signc->AddChild(octsep);
	}

	// put lights all along the right side
	for (unsigned i = 0; i < (unsigned)fabs(SIGN_HEIGHT); i++)
	{
		CSgPtr<CSgMaterial> octmat = new CSgMaterial(50.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f);
		CSgPtr<CSgSeparator> octsep = new CSgSeparator();
		CSgPtr<CSgTranslate> octtrans = new CSgTranslate(SIGN_DEPTH+0.05f, 0.5+(double)i, 0); // cylinder is centered (0.05 = 0.1/2.)
		CSgPtr<CSgOctagonalCylinder> octcyl = new CSgOctagonalCylinder(0.1f, 0.1f);

		m_sign_mat_right[i] = octmat;

		octmat->SetChild(octcyl);
		octtrans->SetChild(octmat);
		octsep->SetChild(octtrans);
		signc->AddChild(octsep);
	}

	// near x face
	sign->AddNormal(CGrVector(-1, 0, 0));
	sign->AddVertex(CGrVector(0, 0, 0));
	sign->AddVertex(CGrVector(0, 0, r_z));
	sign->AddVertex(CGrVector(0, SIGN_HEIGHT, r_z));
	sign->AddVertex(CGrVector(0, SIGN_HEIGHT, 0));
	sign->AddFlatQuad(0, 1, 2, 3, 0);

	// far x face
	sign->AddNormal(CGrVector(1, 0, 0));
	sign->AddVertex(CGrVector(SIGN_DEPTH, SIGN_HEIGHT, 0));
	sign->AddVertex(CGrVector(SIGN_DEPTH, SIGN_HEIGHT, r_z));
	sign->AddVertex(CGrVector(SIGN_DEPTH, 0, r_z));
	sign->AddVertex(CGrVector(SIGN_DEPTH, 0, 0));
	sign->AddFlatQuad(4, 5, 6, 7, 1);

	// bottom face
	sign->AddNormal(CGrVector(0, -1, 0));
	sign->AddVertex(CGrVector(0, 0, 0));
	sign->AddVertex(CGrVector(SIGN_DEPTH, 0, 0));
	sign->AddVertex(CGrVector(SIGN_DEPTH, 0, r_z));
	sign->AddVertex(CGrVector(0, 0, r_z));
	sign->AddFlatQuad(8, 9, 10, 11, 2);




	// near z face
	sign->AddNormal(CGrVector(0, 0, 1));
	sign->AddVertex(CGrVector(0, SIGN_HEIGHT, 0));
	sign->AddVertex(CGrVector(SIGN_DEPTH, SIGN_HEIGHT, 0));
	sign->AddVertex(CGrVector(SIGN_DEPTH, 0, 0));
	sign->AddVertex(CGrVector(0, 0, 0));
	sign->AddFlatQuad(12, 13, 14, 15, 3);
	

	

	CSgPtr<CSgTexture> tex = new CSgTexture(m_texturesign);

	// far z face(the one that needs to be textured with the sign)
	sign->AddNormal(CGrVector(0, 0, -1));
	sign->AddVertex(CGrVector(0, 0, r_z));
	sign->AddVertex(CGrVector(SIGN_DEPTH, 0, r_z));
	sign->AddVertex(CGrVector(SIGN_DEPTH, SIGN_HEIGHT, r_z));
	sign->AddVertex(CGrVector(0, SIGN_HEIGHT, r_z));
	//sign->AddFlatQuad(16, 17, 18, 19, 4);
	sign->AddFlatTexturedQuad(16, 17, 18, 19, 4, CGrVector(0, 1), CGrVector(0, 0), CGrVector(1, 0), CGrVector(1, 1));

	tex->SetChild(sign);

	// top face
	sign->AddNormal(CGrVector(0, 1, 0));
	sign->AddVertex(CGrVector(0, SIGN_HEIGHT, r_z));
	sign->AddVertex(CGrVector(SIGN_DEPTH, SIGN_HEIGHT, r_z));
	sign->AddVertex(CGrVector(SIGN_DEPTH, SIGN_HEIGHT, 0));
	sign->AddVertex(CGrVector(0, SIGN_HEIGHT, 0));
	sign->AddFlatQuad(20, 21, 22, 23, 5);


	trans2->SetChild(tex);
	rot2->SetChild(trans2);
	sep2->SetChild(rot2);

	
	signc->AddChild(sep2);
	return signc;
}

CSgPtr<CSgComposite> FerrisWheelFactory::MakeSeat()
{
	CSgPtr<CSgComposite> seatc = new CSgComposite();

	const float r_z = 0.4f;

	CSgPtr<CSgSeparator> sep1 = new CSgSeparator();
	CSgPtr<CSgTranslate> trans = new CSgTranslate(0, -SIDE_DEPTH, 0);
	CSgPtr<CSgRotate> rot = new CSgRotate(0.0, 0, 0, 1);
	CSgPtr<CSgMesh> seat = new CSgMesh();

	// near x face
	seat->AddNormal(CGrVector(-1, 0, 0));
	seat->AddVertex(CGrVector(0, 0, 0));
	seat->AddVertex(CGrVector(0, 0, r_z));
	seat->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat->AddFlatQuad(0, 1, 2, 3, 0);

	// far x face
	seat->AddNormal(CGrVector(1, 0, 0));
	seat->AddVertex(CGrVector(SIDE_WIDTH, SIDE_HEIGHT, 0));
	seat->AddVertex(CGrVector(SIDE_WIDTH, SIDE_HEIGHT, r_z));
	seat->AddVertex(CGrVector(SIDE_WIDTH, 0, r_z));
	seat->AddVertex(CGrVector(SIDE_WIDTH, 0, 0));
	seat->AddFlatQuad(4, 5, 6, 7, 1);

	// bottom face
	seat->AddNormal(CGrVector(0, -1, 0));
	
	seat->AddVertex(CGrVector(0, 0, 0));
	seat->AddVertex(CGrVector(SIDE_WIDTH, 0, 0));
	seat->AddVertex(CGrVector(SIDE_WIDTH, 0, r_z));
	seat->AddVertex(CGrVector(0, 0, r_z));
	seat->AddFlatQuad(8, 9, 10, 11, 2);

	// near z face
	seat->AddNormal(CGrVector(0, 0, 1));
	seat->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat->AddVertex(CGrVector(SIDE_WIDTH, SIDE_HEIGHT, 0));
	seat->AddVertex(CGrVector(SIDE_WIDTH, 0, 0));
	seat->AddVertex(CGrVector(0, 0, 0));
	seat->AddFlatQuad(12, 13, 14, 15, 3);

	// far z face
	seat->AddNormal(CGrVector(0, 0, -1));
	seat->AddVertex(CGrVector(0, 0, r_z));
	seat->AddVertex(CGrVector(SIDE_WIDTH, 0, r_z));
	seat->AddVertex(CGrVector(SIDE_WIDTH, SIDE_HEIGHT, r_z));
	seat->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat->AddFlatQuad(16, 17, 18, 19, 4);

	// top face
	seat->AddNormal(CGrVector(0, 1, 0));
	seat->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat->AddVertex(CGrVector(SIDE_WIDTH, SIDE_HEIGHT, r_z));
	seat->AddVertex(CGrVector(SIDE_WIDTH, SIDE_HEIGHT, 0));
	seat->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat->AddFlatQuad(20, 21, 22, 23, 5);






	CSgPtr<CSgSeparator> sep2 = new CSgSeparator();
	CSgPtr<CSgRotate> rot2 = new CSgRotate(270.0, 0, 0, 1);
	//CSgPtr<CSgTranslate> trans2 = new CSgTranslate(-SEAT_DEPTH, 0, 0);
	CSgPtr<CSgTranslate> trans2 = new CSgTranslate(-SIDE_HEIGHT, 0, 0);
	CSgPtr<CSgMesh> seat2 = new CSgMesh();

	// near x face
	seat2->AddNormal(CGrVector(-1, 0, 0));
	seat2->AddVertex(CGrVector(0, 0, 0));
	seat2->AddVertex(CGrVector(0, 0, r_z));
	seat2->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat2->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat2->AddFlatQuad(0, 1, 2, 3, 0);

	// far x face
	seat2->AddNormal(CGrVector(1, 0, 0));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, 0));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, r_z));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, 0, r_z));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, 0, 0));
	seat2->AddFlatQuad(4, 5, 6, 7, 1);

	// bottom face
	seat2->AddNormal(CGrVector(0, -1, 0));
	seat2->AddVertex(CGrVector(0, 0, 0));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, 0, 0));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, 0, r_z));
	seat2->AddVertex(CGrVector(0, 0, r_z));
	seat2->AddFlatQuad(8, 9, 10, 11, 2);

	// near z face
	seat2->AddNormal(CGrVector(0, 0, 1));
	seat2->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, 0));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, 0, 0));
	seat2->AddVertex(CGrVector(0, 0, 0));
	seat2->AddFlatQuad(12, 13, 14, 15, 3);

	// far z face
	seat2->AddNormal(CGrVector(0, 0, -1));
	seat2->AddVertex(CGrVector(0, 0, r_z));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, 0, r_z));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, r_z));
	seat2->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat2->AddFlatQuad(16, 17, 18, 19, 4);

	// top face
	seat2->AddNormal(CGrVector(0, 1, 0));
	seat2->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, r_z));
	seat2->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, 0));
	seat2->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat2->AddFlatQuad(20, 21, 22, 23, 5);







	CSgPtr<CSgSeparator> sep3 = new CSgSeparator();
	CSgPtr<CSgRotate> rot3 = new CSgRotate(270.0, 0, 0, 1);
	//CSgPtr<CSgTranslate> trans2 = new CSgTranslate(-SEAT_DEPTH, 0, 0);
	CSgPtr<CSgTranslate> trans3 = new CSgTranslate(-SIDE_HEIGHT, SIDE_WIDTH, 0);
	CSgPtr<CSgMesh> seat3 = new CSgMesh();

	// near x face
	seat3->AddNormal(CGrVector(-1, 0, 0));
	seat3->AddVertex(CGrVector(0, 0, 0));
	seat3->AddVertex(CGrVector(0, 0, r_z));
	seat3->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat3->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat3->AddFlatQuad(0, 1, 2, 3, 0);

	// far x face
	seat3->AddNormal(CGrVector(1, 0, 0));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, 0));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, r_z));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, 0, r_z));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, 0, 0));
	seat3->AddFlatQuad(4, 5, 6, 7, 1);

	// bottom face
	seat3->AddNormal(CGrVector(0, -1, 0));
	seat3->AddVertex(CGrVector(0, 0, 0));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, 0, 0));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, 0, r_z));
	seat3->AddVertex(CGrVector(0, 0, r_z));
	seat3->AddFlatQuad(8, 9, 10, 11, 2);

	// near z face
	seat3->AddNormal(CGrVector(0, 0, 1));
	seat3->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, 0));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, 0, 0));
	seat3->AddVertex(CGrVector(0, 0, 0));
	seat3->AddFlatQuad(12, 13, 14, 15, 3);

	// far z face
	seat3->AddNormal(CGrVector(0, 0, -1));
	seat3->AddVertex(CGrVector(0, 0, r_z));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, 0, r_z));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, r_z));
	seat3->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat3->AddFlatQuad(16, 17, 18, 19, 4);

	// top face
	seat3->AddNormal(CGrVector(0, 1, 0));
	seat3->AddVertex(CGrVector(0, SIDE_HEIGHT, r_z));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, r_z));
	seat3->AddVertex(CGrVector(SIDE_DEPTH, SIDE_HEIGHT, 0));
	seat3->AddVertex(CGrVector(0, SIDE_HEIGHT, 0));
	seat3->AddFlatQuad(20, 21, 22, 23, 5);

	/* outer bars */

	CSgPtr<CSgSeparator> sep4 = new CSgSeparator();
	CSgPtr<CSgComposite> comp4 = new CSgComposite();
	CSgPtr<CSgTranslate> trans_par = new CSgTranslate(0.05f, SIDE_DEPTH/2., 0); // help center the bars (oct cyl needs SIDE_DEPTH/2. for y, reg cyl does not)
	for (int i = 0; i < 10; i++)
	{
		CSgPtr<CSgTranslate> trans4 = new CSgTranslate(0.1f * i, -SIDE_DEPTH + SIDE_HEIGHT, SIDE_DEPTH*2);
		CSgPtr<CSgSeparator> cylsep = new CSgSeparator();
		CSgPtr<CSgOctagonalCylinder> cyl = new CSgOctagonalCylinder(SIDE_DEPTH, 0.01f);
		trans4->SetChild(cyl);
		cylsep->SetChild(trans4);
		comp4->AddChild(cylsep);
	}

	/* outer bars z=-SIDE_DEPTH*2 */

	CSgPtr<CSgSeparator> sep5 = new CSgSeparator();
	CSgPtr<CSgComposite> comp5 = new CSgComposite();
	CSgPtr<CSgTranslate> trans_par2 = new CSgTranslate(0.05f, SIDE_DEPTH/2., -SIDE_DEPTH*2); // help center the bars (oct cyl needs SIDE_DEPTH/2. for y, reg cyl does not)
	for (int i = 0; i < 10; i++)
	{
		CSgPtr<CSgTranslate> trans5 = new CSgTranslate(0.1f * i, -SIDE_DEPTH + SIDE_HEIGHT, SIDE_DEPTH*2);
		CSgPtr<CSgSeparator> cylsep = new CSgSeparator();
		CSgPtr<CSgOctagonalCylinder> cyl = new CSgOctagonalCylinder(SIDE_DEPTH, 0.01f);
		trans5->SetChild(cyl);
		cylsep->SetChild(trans5);
		comp5->AddChild(cylsep);
	}

	rot->SetChild(seat);
	trans->SetChild(rot);
	sep1->SetChild(trans);

	trans2->SetChild(seat2);
	rot2->SetChild(trans2);
	sep2->SetChild(rot2);

	trans3->SetChild(seat3);
	rot3->SetChild(trans3);
	sep3->SetChild(rot3);

	trans_par->SetChild(comp4);
	sep4->SetChild(trans_par);

	trans_par2->SetChild(comp5);
	sep5->SetChild(trans_par2);

	seatc->AddChild(sep1);
	seatc->AddChild(sep2);
	seatc->AddChild(sep3);
	seatc->AddChild(sep4);
	seatc->AddChild(sep5);



	return seatc;
}

CSgObject* FerrisWheelFactory::Create()
{
	CSgPtr<CSgComposite> center = new CSgComposite();
	//CSgPtr<CSgSeparator> separator1 = new CSgSeparator();
	
	const float WHEEL_RIM_DEPTH = 1.0f;
	const float SPOKE_LENGTH = 10.0f;

	const float STARTING_Y = 5.0f;
	const float c_x = 0.0f;
	const float c_y = 0.0f;
	const float c_z = 0.0f;
	const float r_x = SPOKE_LENGTH/2.0f;
	const float r_y = SPOKE_LENGTH/2.0f;
	const float r_z = 1.0f;

	CSgPtr<CSgComposite> seat_comp = new CSgComposite();
	CSgPtr<CSgRotateAroundPoint> anim_rot2 = new CSgRotateAroundPoint(0, SPOKE_LENGTH/2., STARTING_Y + SPOKE_LENGTH/2., 0, 1, 0, 0);
	for (unsigned i=0;i<NUM_SEATS;i++)
	{
		
		CSgPtr<CSgSeparator> seat_sep = new CSgSeparator();
		//CSgPtr<CSgRotateAroundPoint> seat_upright = new CSgRotateAroundPoint(0, SIDE_DEPTH,-SIDE_DEPTH/2. ,0, 1, 0, 0);
		CSgPtr<CSgTranslate> seat_trans2 = new CSgTranslate(0, STARTING_Y + r_y + c_y + SIDE_DEPTH/2., -SIDE_DEPTH + c_x);

		// help prevent migration of cars during animation (undo some translation stuff done by MakeSeat())
		CSgPtr<CSgRotateAroundPoint> seat_upright = new CSgRotateAroundPoint(0, -SIDE_DEPTH/2., -SIDE_DEPTH/2., SIDE_DEPTH, 1, 0, 0);
		//CSgPtr<CSgTranslate> seat_trans = new CSgTranslate(-5.0f, 5.0f + r_y, 5.0f);
		// x and z axis are switched here

		//CSgPtr<CSgTranslate> seat_trans = new CSgTranslate(0, 2*STARTING_Y + c_y + SIDE_DEPTH/2 + (r_y+SIDE_DEPTH/2.)*sin(2*GR_PI/(double)NUM_SEATS * i), -SIDE_DEPTH + c_x + (r_x+SIDE_DEPTH)*cos(2*GR_PI/(double)NUM_SEATS * i));
		//CSgPtr<CSgTranslate> seat_trans = new CSgTranslate(0, STARTING_Y + r_y + c_y + SIDE_DEPTH/2. + (r_y + SIDE_DEPTH/2.)*sin(2*GR_PI/(double)NUM_SEATS * i), -SIDE_DEPTH + c_x + (r_x+SIDE_DEPTH)*cos(2*GR_PI/(double)NUM_SEATS * i));
		//CSgPtr<CSgTranslate> seat_trans = new CSgTranslate(0, STARTING_Y + r_y + c_y + SIDE_DEPTH/2. + (r_y)*sin(2*GR_PI/(double)NUM_SEATS * i), -SIDE_DEPTH + c_x + (r_x)*cos(2*GR_PI/(double)NUM_SEATS * i));
		CSgPtr<CSgTranslate> seat_trans = new CSgTranslate(0, (r_y + SIDE_DEPTH/2.)*sin(2*GR_PI/(double)NUM_SEATS * i), (r_x+SIDE_DEPTH)*cos(2*GR_PI/(double)NUM_SEATS * i));

		
		seat_upright->SetChild(MakeSeat());
		seat_trans->SetChild(seat_upright);
		seat_trans2->SetChild(seat_trans);
		seat_sep->SetChild(seat_trans2);

		/*seat_trans->SetChild(MakeSeat());
		seat_upright->SetChild(seat_trans);
		seat_sep->SetChild(seat_upright);*/

		//m_FerrisWheel->AddChild(seat_sep);
		seat_comp->AddChild(seat_sep);
		m_rotate_point_2[i] = seat_upright;
	}
	anim_rot2->SetChild(seat_comp);
	m_rotate_point_5 = anim_rot2;
	CSgPtr<CSgSeparator> sep_rot2 = new CSgSeparator();
	sep_rot2->SetChild(anim_rot2);
	m_FerrisWheel->AddChild(sep_rot2);

	CSgPtr<CSgTranslate> anim_trans = new CSgTranslate(0, STARTING_Y, 0);
	CSgPtr<CSgRotateAroundPoint> anim_rot = new CSgRotateAroundPoint(0, SPOKE_LENGTH/2., SPOKE_LENGTH/2., 0, 1, 0, 0);

	// record our point of rotation
	m_rotate_point_1 = anim_rot;

	CSgPtr<CSgTranslate> translate1 = new CSgTranslate(0., SPOKE_LENGTH/2., 0.);
	CSgPtr<CSgComposite> comp = new CSgComposite();
	
	for (unsigned i=0;i<NUM_SPOKES;i++)
	{
		
		//CSgPtr<CSgOctagonalCylinder> oct = new CSgOctagonalCylinder(5.0f, 0.2f);
		//CSgPtr<CSgMaterial> mat = new CSgMaterial();
		CSgPtr<CSgComposite> comp3 = new CSgComposite();
		CSgPtr<CSgTranslate> trans = new CSgTranslate(r_z/2., 0., 0.);
		CSgPtr<CSgRotateAroundPoint> rot = new CSgRotateAroundPoint(180./(double)NUM_SPOKES * (double)i, 0,0,0,1,0,0);
		CSgPtr<CSgOctagonalCylinder> oct = new CSgOctagonalCylinder(SPOKE_LENGTH-WHEEL_RIM_DEPTH, 0.05f);
		rot->SetChild(oct);
		//comp_spokes->AddChild(rot);
		trans->SetChild(rot);
		comp3->AddChild(trans);
		comp->AddChild(comp3);
		
	}

	CSgPtr<CSgRotateAroundPoint> rot = new CSgRotateAroundPoint(90.0, 0, 0, 0, 0, 1, 0);
	CSgPtr<CSgMesh> mesh = new CSgMesh();
	CSgPtr<CSgComposite> comp2 = new CSgComposite();
	
	CSgPtr<CSgTexture> tex = new CSgTexture(m_texture1);

	/* BEGIN OUTER FACE */
	for (unsigned i=0;i<NUM_SIDES;i++)
	{
		//a
		mesh->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * i), 0));

		//b
		mesh->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), 0));

		//c
		mesh->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), r_z));

		//d
		mesh->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * i), r_z));
	}
	for (unsigned i=0;i<NUM_SIDES*4;i+=4)
	{
		//mesh->AddFlatTexturedQuad(i, i+1, i+2, i+3, i, CGrVector(0, 5), CGrVector(0, 0), CGrVector(5, 0), CGrVector(5, 5));
		mesh->AddFlatTexturedQuad(i, i+1, i+2, i+3, i, CGrVector(0, 1), CGrVector(0, 0), CGrVector(1, 0), CGrVector(1, 1));
	}
	/* END OUTER FACE */

	tex->SetChild(mesh);
	

	CSgPtr<CSgTexture> tex3 = new CSgTexture(m_texture3);

	CSgPtr<CSgMaterial> mat1 = new CSgMaterial(50, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
	//CSgPtr<CSgMaterial> mat2 = new CSgMaterial(50, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	CSgPtr<CSgMesh> mesh2 = new CSgMesh();
	CSgPtr<CSgMesh> mesh3 = new CSgMesh();
	
	/* BEGIN FRONT FACE */
	for (unsigned i=0;i<NUM_SIDES;i++)
	{
		mesh2->AddNormal(CGrVector(-1, 0, 0));
		mesh2->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * i), 0));
		mesh2->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), 0));
		mesh2->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), 0));
		mesh2->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * i), 0));
		
		mesh3->AddNormal(CGrVector(1, -1, -1));
		mesh3->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * i), r_z));
		mesh3->AddVertex(CGrVector(c_x + r_x*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + r_y*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), r_z));
		mesh3->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), r_z));
		mesh3->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * i), r_z));
	}
	for (unsigned i=0;i<NUM_SIDES*4;i+=4)
	{
		mesh2->AddFlatQuad(i, i+1, i+2, i+3, i);
		//mesh2->AddFlatTexturedQuad(i, i+1, i+2, i+3, i, CGrVector(0, 1), CGrVector(1, 1), CGrVector(1, 0), CGrVector(0, 0));
		//mesh3->AddFlatQuad(i, i+1, i+2, i+3, i);
		mesh3->AddFlatTexturedQuad(i, i+1, i+2, i+3, i, CGrVector(0, 1), CGrVector(1, 1), CGrVector(1, 0), CGrVector(0, 0));
	}
	/* END FRONT FACE */
	
	//tex3->SetChild(mesh2);
	mat1->SetChild(mesh2);
	tex3->SetChild(mesh3);
	
	CSgPtr<CSgTexture> tex2 = new CSgTexture(m_texture2);
	/* BEGIN INNER FACE */
	CSgPtr<CSgMesh> mesh4 = new CSgMesh();
	for (unsigned i=0;i<NUM_SIDES;i++)
	{
		mesh4->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * i), r_z));
		mesh4->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), r_z));
		mesh4->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * (i+1)), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * (i+1)), 0));
		mesh4->AddVertex(CGrVector(c_x + (-WHEEL_RIM_DEPTH/2.+r_x)*cos(2*GR_PI/(double)NUM_SIDES * i), c_y + (-WHEEL_RIM_DEPTH/2.+r_y)*sin(2*GR_PI/(double)NUM_SIDES * i), 0));
	}
	for (unsigned i=0;i<NUM_SIDES*4;i+=4)
	{
		//mesh4->AddFlatQuad(i, i+1, i+2, i+3, i);
		mesh4->AddFlatTexturedQuad(i, i+1, i+2, i+3, i, CGrVector(0, 0), CGrVector(0, 1), CGrVector(1, 1), CGrVector(1, 0));
	}
	/* END INNER FACE */
	tex2->SetChild(mesh4);

	mesh->ComputeSmoothNormals();
	mesh2->ComputeSmoothNormals();
	mesh3->ComputeSmoothNormals();
	mesh4->ComputeSmoothNormals();

	CSgPtr<CSgComposite> comp_wheelfaces = new CSgComposite();
	comp_wheelfaces->AddChild(tex); // mesh
	comp_wheelfaces->AddChild(mat1); // mesh2
	comp_wheelfaces->AddChild(tex3); // mesh3
	comp_wheelfaces->AddChild(tex2); // mesh4

	rot->SetChild(comp_wheelfaces);
	comp->AddChild(rot);

	translate1->SetChild(comp);
	center->AddChild(translate1);
	anim_rot->SetChild(center);
	anim_trans->SetChild(anim_rot);
	CSgPtr<CSgSeparator> main_sep = new CSgSeparator();
	main_sep->SetChild(anim_trans);
	m_FerrisWheel->AddChild(main_sep);

	// make our sign

	CSgPtr<CSgSeparator> sign_sep = new CSgSeparator();
	CSgPtr<CSgComposite> sign_comp = new CSgComposite();
	CSgPtr<CSgTranslate> sign_trans = new CSgTranslate(-10.0f, 6.0f, 10.0f);

	CSgPtr<CSgTranslate> sign_cyl_trans = new CSgTranslate(SIGN_DEPTH / 2., -6.3f, 0);
	CSgPtr<CSgCylinder> sign_cyl = new CSgCylinder(6.0f, 0.05f);
	
	sign_trans->SetChild(MakeSign());
	sign_comp->AddChild(sign_trans);
	sign_cyl_trans->SetChild(sign_cyl);
	sign_comp->AddChild(sign_cyl_trans);
	sign_sep->SetChild(sign_comp);

	m_FerrisWheel->AddChild(sign_sep);

	// make our support

	CSgPtr<CSgSeparator> support_sep = new CSgSeparator();
	CSgPtr<CSgComposite> support_comp = new CSgComposite();
	CSgPtr<CSgRotate> support_rot = new CSgRotate(90.0f, 0, 0, 1.0);
	CSgPtr<CSgTranslate> support_trans = new CSgTranslate(3.0f, STARTING_Y + r_y, 0);
	CSgPtr<CSgCylinder> support_cyl = new CSgCylinder(1.5f, 0.3f);
	CSgPtr<CSgCylinder> support_connect_cyl = new CSgCylinder(3.0f - r_z/2., 0.07f);

	// direct the cylinder to our point on the ground
	//CGrVector dir = (CGrVector(3.0, STARTING_Y + r_y, 0) - CGrVector(5.0, 0.0, -1.5, 0));
	//dir.Normalize3();

	/*FILE * f = fopen("c:\\temp.txt", "w+");
	if (f != NULL)
	{
		dir.Normalize3();
		fprintf(f, "dir: (%lf, %lf, %lf)\n", dir.X(), dir.Y(), dir.Z());
		fclose(f);
	}*/
/*
	CSgPtr<CSgSeparator> testsep1 = new CSgSeparator();
	CSgPtr<CSgTranslate> testtrans1 = new CSgTranslate(5.0, 0.0, -1.5); // starting point
	CSgPtr<CSgCylinder> cylv = new CSgCylinder(dir.Length3(), 0.07f);
	dir.Normalize3();
	//CSgPtr<CSgRotate> testrot1 = new CSgRotate(360.0, dir);
	CSgPtr<CSgRotate> testrot1 = new CSgRotate(360.0 * dir.X(), 1, 0, 0);
	CSgPtr<CSgRotate> testrot2 = new CSgRotate(360.0 * dir.Y(), 0, 1, 0);
	CSgPtr<CSgRotate> testrot3 = new CSgRotate(360.0 * dir.Z(), 0, 0, 1);
	testrot3->SetChild(cylv);
	testrot2->SetChild(testrot3);
	testrot1->SetChild(testrot2);
	testtrans1->SetChild(testrot1);
	testsep1->SetChild(testtrans1);*/
	

//(3.0f, 0.0f, 1.5f) - (3.0f, STARTING_Y + r_y, 0)
	
	/*CSgPtr<CSgTranslate> testtrans1 = new CSgTranslate(3.0f, 0.0f, 1.5f);
	CSgPtr<CSgCylinder> testcyl1 = new CSgCylinder(0.5f, 0.5f);
	testtrans1->SetChild(testcyl1);
	testsep1->SetChild(testtrans1);*/
/*
	CSgPtr<CSgSeparator> testsep2 = new CSgSeparator();
	CSgPtr<CSgTranslate> testtrans2 = new CSgTranslate(5.0f, 0.0f, -1.5f);
	CSgPtr<CSgCylinder> testcyl2 = new CSgCylinder(0.5f, 0.5f);
	testtrans2->SetChild(testcyl2);
	testsep2->SetChild(testtrans2);*/

	support_comp->AddChild(support_cyl);
	support_comp->AddChild(support_connect_cyl);

	CSgPtr<CSgComposite> support_comp2 = new CSgComposite();

	{
		CSgPtr<CSgSeparator> support_line_sep_1 = new CSgSeparator();
		CSgPtr<CSgRotate> support_line_rot_1 = new CSgRotate(20.0f, 1, 0, 0);
		CSgPtr<CSgRotate> support_line_rot_2 = new CSgRotate(90.0f, 0, 0, 1);
		CSgPtr<CSgCylinder> support_line_cyl_1 = new CSgCylinder(STARTING_Y + r_y + 1.75f, 0.07f);

		support_line_rot_1->SetChild(support_line_cyl_1);
		support_line_rot_2->SetChild(support_line_rot_1);
		support_line_sep_1->SetChild(support_line_rot_2);

		support_comp2->AddChild(support_line_sep_1);
	}

	{
		CSgPtr<CSgSeparator> support_line_sep_1 = new CSgSeparator();
		CSgPtr<CSgRotate> support_line_rot_1 = new CSgRotate(-20.0f, 1, 0, 0);
		CSgPtr<CSgRotate> support_line_rot_2 = new CSgRotate(90.0f, 0, 0, 1);
		CSgPtr<CSgCylinder> support_line_cyl_1 = new CSgCylinder(STARTING_Y + r_y + 1.75f, 0.07f);

		support_line_rot_1->SetChild(support_line_cyl_1);
		support_line_rot_2->SetChild(support_line_rot_1);
		support_line_sep_1->SetChild(support_line_rot_2);

		support_comp2->AddChild(support_line_sep_1);
	}



	{
		CSgPtr<CSgSeparator> support_line_sep_1 = new CSgSeparator();
		CSgPtr<CSgSeparator> support_line_sep_2 = new CSgSeparator();
		CSgPtr<CSgTranslate> support_line_trans_1 = new CSgTranslate(0, 0.5, 0);
		CSgPtr<CSgRotate> support_line_rot_1 = new CSgRotate(20.0f, 1, 0, 0);
		CSgPtr<CSgRotate> support_line_rot_2 = new CSgRotate(90.0f, 0, 0, 1);
		CSgPtr<CSgCylinder> support_line_cyl_1 = new CSgCylinder(STARTING_Y + r_y + 1.75f, 0.07f);

		support_line_rot_1->SetChild(support_line_cyl_1);
		support_line_rot_2->SetChild(support_line_rot_1);
		support_line_sep_1->SetChild(support_line_rot_2);
		support_line_trans_1->SetChild(support_line_sep_1);

		support_line_sep_2->SetChild(support_line_trans_1);
		support_comp2->AddChild(support_line_sep_2);
	}

	{
		CSgPtr<CSgSeparator> support_line_sep_1 = new CSgSeparator();
		CSgPtr<CSgSeparator> support_line_sep_2 = new CSgSeparator();
		CSgPtr<CSgTranslate> support_line_trans_1 = new CSgTranslate(0, 0.5, 0);
		CSgPtr<CSgRotate> support_line_rot_1 = new CSgRotate(-20.0f, 1, 0, 0);
		CSgPtr<CSgRotate> support_line_rot_2 = new CSgRotate(90.0f, 0, 0, 1);
		CSgPtr<CSgCylinder> support_line_cyl_1 = new CSgCylinder(STARTING_Y + r_y + 1.75f, 0.07f);

		support_line_rot_1->SetChild(support_line_cyl_1);
		support_line_rot_2->SetChild(support_line_rot_1);
		support_line_sep_1->SetChild(support_line_rot_2);
		support_line_trans_1->SetChild(support_line_sep_1);

		support_line_sep_2->SetChild(support_line_trans_1);
		support_comp2->AddChild(support_line_sep_2);
	}

	{
		CSgPtr<CSgSeparator> support_line_sep_1 = new CSgSeparator();
		CSgPtr<CSgSeparator> support_line_sep_2 = new CSgSeparator();
		CSgPtr<CSgTranslate> support_line_trans_1 = new CSgTranslate(0, 1.0, 0);
		CSgPtr<CSgRotate> support_line_rot_1 = new CSgRotate(20.0f, 1, 0, 0);
		CSgPtr<CSgRotate> support_line_rot_2 = new CSgRotate(90.0f, 0, 0, 1);
		CSgPtr<CSgCylinder> support_line_cyl_1 = new CSgCylinder(STARTING_Y + r_y + 1.75f, 0.07f);

		support_line_rot_1->SetChild(support_line_cyl_1);
		support_line_rot_2->SetChild(support_line_rot_1);
		support_line_sep_1->SetChild(support_line_rot_2);
		support_line_trans_1->SetChild(support_line_sep_1);

		support_line_sep_2->SetChild(support_line_trans_1);
		support_comp2->AddChild(support_line_sep_2);
	}

	{
		CSgPtr<CSgSeparator> support_line_sep_1 = new CSgSeparator();
		CSgPtr<CSgSeparator> support_line_sep_2 = new CSgSeparator();
		CSgPtr<CSgTranslate> support_line_trans_1 = new CSgTranslate(0, 1.0, 0);
		CSgPtr<CSgRotate> support_line_rot_1 = new CSgRotate(-20.0f, 1, 0, 0);
		CSgPtr<CSgRotate> support_line_rot_2 = new CSgRotate(90.0f, 0, 0, 1);
		CSgPtr<CSgCylinder> support_line_cyl_1 = new CSgCylinder(STARTING_Y + r_y + 1.75f, 0.07f);

		support_line_rot_1->SetChild(support_line_cyl_1);
		support_line_rot_2->SetChild(support_line_rot_1);
		support_line_sep_1->SetChild(support_line_rot_2);
		support_line_trans_1->SetChild(support_line_sep_1);

		support_line_sep_2->SetChild(support_line_trans_1);
		support_comp2->AddChild(support_line_sep_2);
	}


	// fix alignment issues
	CSgPtr<CSgTranslate> support_trans_fix = new CSgTranslate(-0.3, 0.3, 0);
	
	
	support_trans_fix->SetChild(support_comp2);
	support_comp->AddChild(support_trans_fix);
	
	support_rot->SetChild(support_comp);
	support_trans->SetChild(support_rot);
	support_sep->SetChild(support_trans);
	m_FerrisWheel->AddChild(support_sep);


	//m_FerrisWheel->AddChild(testsep1);
	//m_FerrisWheel->AddChild(testsep2);


	return m_FerrisWheel;
}
